package gui;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
 
public class SearchIconTF extends JTextField{
	private static final long serialVersionUID = 1L;
	
	private Icon icon;
 
    public SearchIconTF(){
        super();
        this.icon = null;
        Border line = BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1, false);
        Border empty = new EmptyBorder(3, 26, 2, 2);
		CompoundBorder border = new CompoundBorder(line, empty);
		setBorder(border);
    }
 
    public void setIcon(Icon icon){
        this.icon = icon;
    }
 
    public Icon getIcon(){
        return this.icon;
    }
 
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if(this.icon!=null){
            int iconHeight = icon.getIconHeight();
            int x = 1;
            int y = (this.getHeight() - iconHeight)/2;
            icon.paintIcon(this, g, x, y);
        }
    }
}